<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>为什么子类的构造函数需要super</title>
</head>
<body>
    
</body>
<script>
    class User{
        constructor(name){
            this.name = name
        }
    }
    class admin extends User{
        constructor(value){
            super(value)  //在construce中的super()代表的是继承父类的方法
            this.sex = value
        }
    }
    let asmins = new admin('jimmy')
    console.log(asmins)  //Must call super constructor in derived class before
    // 没加super()的时候 JS会强制报错 加上super以后 就不会报错了

    console.log(asmins)  //{name: "jimmy", sex: "jimmy"}
</script>
</html>